import {reqCartList, reqDeleteCarById, reqDeleteCartById} from "../../api";

export default ({
    namespaced: true,
    state: {
        cartList: []
    },
    mutations: {
        GETCARTLIST(state, value) {
            state.cartList = value
        }
    },
    actions: {
        // 获取购物车列表数据
        async getCartList({commit}) {
            let result = await reqCartList();
            // console.log(result)
            if (result.code == 200) {
                commit('GETCARTLIST', result.data)
            }
        },
        // 删除购物车的某一个产品
        async deleteCartListBySkuId({commit}, skuId) {
            let result = await reqDeleteCartById(skuId)
            if (result.code == 200) {
                return 'success'
            } else {
                return Promise.reject(new Error('faile'))
            }
        }

    },
    getters: {
        cartList1(state) {
            return state.cartList[0] || {}
        }
    }

})